/**
* 左边菜单
*/
<template>
  <el-menu default-active="2" :collapse="collapsed" collapse-transition router :default-active="$route.path" unique-opened class="el-menu-vertical-demo" background-color="#334157" text-color="#fff" active-text-color="#ffd04b">
    <div class="logobox">
      <img class="logoimg" src="../assets/img/logo.png" alt="">
    </div>
    <el-submenu v-for="menu in allmenu" :key="menu.menuid" :index="menu.menuname">
      <template slot="title">
        <i class="iconfont" :class="menu.icon"></i>
        <span>{{menu.menuname}}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item v-for="chmenu in menu.menus" :index="'/'+chmenu.url" :key="chmenu.menuid">
          <i class="iconfont" :class="chmenu.icon"></i>
          <span>{{chmenu.menuname}}</span>
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>
<script>

  export default {
    name: 'leftnav1',
    data() {
      return {
        collapsed: false,
        allmenu: []
      }
    },
    // 创建完毕状态(里面是操作)
    created() {
      // 获取图形验证码
      let res = {
        success: true,
        data: [
          {
            menuid: 1,
            icon: 'li-icon-xiangmuguanli',
            menuname: '账号管理',
            hasThird: null,
            url: null,
            menus: [
              {
                menuid: 2,
                icon: 'icon-cat-skuQuery',
                menuname: '个人信息',
                hasThird: 'N',
                url: 'system/personal',
                menus: null
              },
              {
                menuid: 3,
                icon: 'icon-cat-skuQuery',
                menuname: '修改密码',
                hasThird: 'N',
                url: 'system/changepwd',
                menus: null
              },
              {
                menuid: 4,
                icon: 'icon-cat-skuQuery',
                menuname: '部门设置',
                hasThird: 'N',
                url: 'system/department',
                menus: null
              },
              {
                menuid: 5,
                icon: 'icon-cat-skuQuery',
                menuname: '员工账号',
                hasThird: 'N',
                url: 'system/useraccount',
                menus: null
              },
              {
                menuid: 6,
                icon: 'icon-cat-skuQuery',
                menuname: '角色管理',
                hasThird: 'N',
                url: 'system/rolemanage',
                menus: null
              }
            ]
          },
          {
            menuid: 30,
            icon: 'li-icon-dingdanguanli',
            menuname: '商户门店',
            hasThird: null,
            url: null,
            menus: [
              {
                menuid: 31,
                icon: 'icon-order-manage',
                menuname: '商户资料',
                hasThird: 'N',
                url: 'system/MerchantInformation',
                menus: null
              },
              {
                menuid: 32,
                icon: 'icon-order-manage',
                menuname: '门店管理',
                hasThird: 'N',
                url: 'system/StoreManager',
                menus: null
              },
              {
                menuid: 33,
                icon: 'icon-order-manage',
                menuname: '终端管理',
                hasThird: 'N',
                url: 'system/TerminalManager',
                menus: null
              }
            ]
          },
          {
            menuid: 50,
            icon: 'li-icon-xitongguanli',
            menuname: '平台租用',
            hasThird: null,
            url: null,
            menus: [
              {
                menuid: 51,
                icon: 'icon-cus-manage',
                menuname: '购买服务',
                hasThird: 'N',
                url: 'system/PurchaseServices',
                menus: null
              },
              {
                menuid: 52,
                icon: 'icon-cms-manage',
                menuname: '购买记录',
                hasThird: 'N',
                url: 'system/PurchaseServiceManager',
                menus: null
              },
              {
                menuid: 53,
                icon: 'icon-news-manage',
                menuname: '申请发票',
                hasThird: 'N',
                url: 'system/ApplyInvoice',
                menus: null
              },
              {
                menuid: 54,
                icon: 'icon-cs-manage',
                menuname: '发票记录',
                hasThird: 'N',
                url: 'system/InvoiceManager',
                menus: null
              }
            ]
          },
          {
            menuid: 70,
            icon: 'li-icon-shangchengxitongtubiaozitihuayuanwenjian91',
            menuname: '消息管理',
            hasThird: null,
            url: null,
            menus: [
              {
                menuid: 71,
                icon: 'icon-provider-manage',
                menuname: '业务消息',
                hasThird: 'N',
                url: 'sys/BusinessMessage',
                menus: null
              },
              {
                menuid: 72,
                icon: 'icon-provider-manage',
                menuname: '系统公告',
                hasThird: 'N',
                url: 'sys/SystemMessage',
                menus: null
              },
              {
                menuid: 73,
                icon: 'icon-provider-manage',
                menuname: '升级公告',
                hasThird: 'N',
                url: 'sys/UpgradeMessage',
                menus: null
              }
            ]
          },
          {
            menuid: 90,
            icon: 'li-icon-shangchengxitongtubiaozitihuayuanwenjian91',
            menuname: '系统日志',
            hasThird: null,
            url: null,
            menus: [
              {
                menuid: 91,
                icon: 'icon-provider-manage',
                menuname: '登陆日志',
                hasThird: 'N',
                url: 'log/LoginLog',
                menus: null
              },
              {
                menuid: 92,
                icon: 'icon-provider-manage',
                menuname: '操作日志',
                hasThird: 'N',
                url: 'log/OperationLog',
                menus: null
              }
            ]
          }
        ],
        msg: 'success'
      }
      this.allmenu = res.data

      // menu(localStorage.getItem('logintoken'))
      //   .then(res => {
      //     console.log(JSON.stringify(res))
      //     if (res.success) {
      //       this.allmenu = res.data
      //     } else {
      //       this.$message.error(res.msg)
      //       return false
      //     }
      //   })
      //   .catch(err => {
      //     this.$message.error('菜单加载失败，请稍后再试！')
      //   })
      // 监听
      this.$root.Bus.$on('toggle', value => {
        this.collapsed = !value
      })
    }
  }
</script>
<style>
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 240px;
    min-height: 400px;
  }
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    border: none;
    text-align: left;
  }
  .el-menu-item-group__title {
    padding: 0px;
  }
  .el-menu-bg {
    background-color: #1f2d3d !important;
  }
  .el-menu {
    border: none;
  }
  .logobox {
    height: 40px;
    line-height: 40px;
    color: #9d9d9d;
    font-size: 20px;
    text-align: center;
    padding: 20px 0px;
  }
  .logoimg {
    height: 40px;
  }
</style>
